package controllers

import (
	"beeblog/models"

	"github.com/astaxie/beego"
)

// ReplyController 回复控制器
type ReplyController struct {
	beego.Controller
}

// Add 添加回复
func (replyCtl *ReplyController) Add() {
	input := replyCtl.Input()
	tid := input.Get("tid")
	if err := models.AddReply(tid, input.Get("nickname"), input.Get("content")); err != nil {
		beego.Error(err)
	}
	replyCtl.Redirect("/topic/view/"+tid, 302)
}

//Delete 删除回复
func (replyCtl *ReplyController) Delete() {
	if !checkAccount(replyCtl.Ctx) {
		replyCtl.Redirect("/login", 302)
		return
	}

	input := replyCtl.Input()
	rid := input.Get("rid")
	if err := models.DelReply(rid); err != nil {
		beego.Error(err)
	}
	replyCtl.Redirect("/topic/view/"+input.Get("tid"), 302)
}
